import axios from 'axios'

class HttpAxios {
  constructor () {
    this.baseURL = 'http://vlearn2206b.daweilab.com'
  }

    // 拦截器设置
    SetInterceptors = (instance) => {
      instance.interceptors.request.use(config => {
        // 为请求头对象,添加 token 验证的 Authorization 字段
        config.headers.Authorization = sessionStorage.getItem('token')
        // 必须要 return
        return config
      }, err => Promise.reject(err))
      // 响应拦截器
    }

    request (options) {
      // 创建 axios 实例
      const instance = axios.create()
      const config = {
        ...options,
        baseURL: this.baseURL
      }
      this.SetInterceptors(instance)
      return instance(config)
    }
}

export default new HttpAxios()
